int reverse(int x){
    long int result=0;
    int temp=0;
    while(x)
    {
        result = result * 10 + x % 10;
        if(temp != ((int)result / 10))
        {
            return 0;
        }
        temp = result;
        x /= 10;
    }
    return result;
}
